#define DEBUG
#include <cstdio>
#define INF 0x7ffffff
#define MAXN 200
#define MAXM (MAXN*8+1)

using namespace std;

class Graph {
public:
  int n, m=1, ind[MAXN+1], to[MAXM+1], link[MAXM+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void solve(int o, int *ans) {
    static bool book[MAXM+1];
    for (bool flag=true; flag; ) {
      flag = false;
      int min=INF, x;
      for (int i=ind[o]; i; i=link[i]) {
	if (!book[i]) {
	  if (to[i]<min) {
	    min = to[i];
	    x = i;
	  }
	  flag = true;
	}
      }
      if (flag) {
	book[x] = book[x^1] = true;
	solve(min, ans);
      }
    }
    ans[++ans[0]] = o;
  }
};

int main() {
#ifdef DEBUG
  freopen("1319.in", "r", stdin);
  freopen("1319.out", "w", stdout);
#endif

  int n, m;
  scanf("%d %d", &n, &m);
  static Graph g;
  g.n = n;
  for (int i=1; i<=n; i++) {
    int w;
    scanf("%d", &w);
  }

  for (int i=1; i<=m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g.addSide(u, v);
    g.addSide(v, u);
  }

  static int ans[MAXM+1];
  g.solve(1, ans);
  printf("%d\n", ans[0]-1);
  for (int i=ans[0]; i; i--) {
    printf("%d ", ans[i]);
  }

  fcloseall();
  return 0;
}
